﻿#pragma once
#include<iostream>
using namespace std;
#include<assert.h>

// 重载

class Date
{
	friend ostream& operator<<(ostream& out, const Date& d);
	friend istream& operator>>(istream& in, Date& d);
public :
	Date(int year, int month, int day);
	Date(const Date& d)
	{
		_year = d._year;
		_day = d._day;
		_month = d._month;
		//cout << "拷贝构造" << endl;
	}
	int GetMonthDay(int year,int m) const//const Date* this
	{
		static int month[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
		if (m == 2 && ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0)))
		{
			return 29;
		}
		return month[m];

	}
	void print();
	bool CheckDate();
	//const加在this指针*的前面
	// Print隐含的this指针由 Date* const this 变为 const Date* const this
	bool operator<(const Date& d) const;
	bool operator<=(const Date& d) const;
	bool operator>(const Date& d) const;
	bool operator>=(const Date& d) const;
	bool operator==(const Date& d) const;
	bool operator!=(const Date& d) const;
	// d1 += 天数
	Date& operator+=(int day);
	Date operator+(int day) const;
	// d1 -= 天数
	Date& operator-=(int day);
	Date operator-(int day) const;
	// d1 - d2
	int operator-(const Date& d) const;
	// ++d1 -> d1.operator++()
	Date& operator++();
	// d1++ -> d1.operator++(0)
	// 为了区分，构成重载，给后置++，强⾏增加了⼀个int形参
	// 这⾥不需要写形参名，因为接收值是多少不重要，也不需要⽤
	// 这个参数仅仅是为了跟前置++构成重载区分
	Date operator++(int);

	Date& operator--();
	Date operator--(int);

private:
	int _year;
	int _month;
	int _day;
};
